package com.xpffly.design.handler;

import cn.hutool.core.util.RandomUtil;
import com.xpffly.design.handler.service.Handler;
import com.xpffly.design.handler.service.Women;
import com.xpffly.design.handler.service.impl.Father;
import com.xpffly.design.handler.service.impl.Husband;
import com.xpffly.design.handler.service.impl.Son;
import com.xpffly.design.handler.service.impl.WomenImpl;

import java.util.ArrayList;

/**
 * @Author: xpengfei
 * @Date: 2021/4/6 23:13
 * @Description：责任链模式场景类
 */
public class Scene {

    public static void main(String[] args) {
        // 随机生成几个女性对象
        ArrayList<Women> arrayList = new ArrayList<Women>();
        for (int i = 0; i < 6; i++) {
            arrayList.add(new WomenImpl(RandomUtil.randomInt(0, 3), "我要出去逛街！"));
        }
        // 定义三个处理请求的对象
        Handler father = new Father();
        Handler husband = new Husband();
        Handler son = new Son();
        // 设置请求链的处理顺序
        father.setNextHandler(husband);
        husband.setNextHandler(son);
        for (Women women : arrayList) {
            father.handleRequest(women);
        }
    }
}
